﻿<script>
	$(document).ready(function(){
		$("#add_groupe_bdd").click(function(){
			if($("#school_select").val() == "" || $("#nom_groupe").val() == ""){
				alert("Veuillez completer le formulaire !");
				return;
			}
			
			$.ajax({
			  url: "<?php echo base_url(); ?>formulaire/AjaxAddGroupe",
			  type: 'POST',
			  data: {"nom":$("#nom_groupe").val(), "school":$("#school_select").val()},
			  success: function (data) {
				$("#select_group_add").append(data);
			  },
			  error: function () {
				alert("Impossible d'ajouter le groupe pour le moment");
			  }
			});
			
			$("#fake_close").click();
		});
	});
</script>
<div class="container">
	<h2>S'inscrire comme participant</h2>
	<div class="col-md-6 col-lg-6">
		<form class="col-md-6 col-lg-6" action="<?php echo base_url(); ?>formulaire/inscriptionParticipant" method="POST">
			<div class="form-group">
				<label for="texte" class="label">Nom </label>
				<input id="text" type="text" class="form-control" position="center" name="nom" required="required">
			</div>
			<div class="form-group">
				<label for="texte" class="label">Prénom </label>
				<input id="text" type="text" class="form-control" name="prenom" required="required">    
			</div>
			<div class="form-group">
				<label for="texte" class="label">Email(login) </label>
				<input id="text" type="email" class="form-control" name="email" required="required">    
			</div>
			<div class="form-group">
				<label for="texte" class="label">Mot de passe </label>
				<input id="text" type="password" class="form-control" name="pwd" required="required">    
			</div>
			<div class="form-group">
			  <label for="select" class="label">Classe </label>
			  <select class="form-control" name="classe" required="required">
				<option value="" selected="selected">Niveau</option>
				<?php
					foreach($lvlClasse as $lvl){
						echo "<option value=\"".$lvl->PK_LVL."\">".$lvl->LVL_LIB."</option>";
					}
				?>
			  </select>
			</div>
			<div class="form-group">
			  <label for="select" class="label">Rejoindre </label>
			  <select class="form-control" name="groupe" required="required" id="select_group_add">
				<option value="" selected="selected">Groupe</option>
				<?php
					foreach($groupes as $groupe){
						echo "<option value=\"".$groupe->PK_GRP."\">".$groupe->GRP_LIB."</option>";
					}
				?>
			  </select>
			  <p class="ou"> ou </p>		  
			  
			  <div id="html">
				<p><input data-toggle="modal" data-backdrop="false" href="#formulaire" class="btn btn-pop" value="Créer un groupe"></p>
			  </div>
			  <div class="modal fade" id="formulaire">
				<div class="modal-dialog">
				   <div class="modal-content">
					<div class="modal-header">
					  <button type="button" class="close" data-dismiss="modal" id="fake_close">x</button>
					  <h4 class="modal-title">Créer un groupe de projet</h4>
					</div>
					<div class="modal-body">
						<div class="form-group">
						  <label for="nom">Nom du groupe</label>
						  <input type="text" class="form-control" name ="nom" id="nom_groupe" placeholder="Votre nom de groupe">
						</div>
						<div class="form-group">
							<label for="select">Sélectionner </label>
							<select class="form-control" id="school_select">
								<option value="" selected="selected">Les écoles</option>
								<?php
									foreach($schls as $schl){
										echo "<option value=\"".$schl->PK_SCHL."\">".$schl->SCHL_LIB."</option>";
									}
								?>
							</select>
						</div>
						
					</div>
					<div class="modal-footer">
					  <button type="button" class="btn btn-custom" id="add_groupe_bdd">Valider</button>
					</div>
				  </div>
				</div>			  
			</div>	
			<input type="submit" class="btn btn-custom valider" value="Valider" />   
		</form>
	</div>	
</div>